/**
 * MaxTemperature.java
 * TODO 
 * 创建一个Job作业运行MapReduce程序
 */
package com.tjh.hadoop.mapred;

import java.net.InetAddress;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author jahen
 * @date 2016年9月16日
 * @time 下午2:18:38
 * @category Hadoop MapReduce
 */
public class MaxTemperature {
	
	public static void main(String[] args) throws Exception {
		
		InetAddress ip = InetAddress.getLocalHost();
		System.out.println("APP : " + ip);
		
		if (args.length != 2) {
			System.err.println("Usage: MaxTemperature <input path> <output path>");
			System.exit(-1);
		}
		// 创建作业Job实例
		Job job = Job.getInstance();

		job.setJarByClass(MaxTemperature.class);
		// 设置作业名称
		job.setJobName("Max temperature");
		// 输入路径
		FileInputFormat.addInputPath(job, new Path(args[0]));
		// 输出路径
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		// 设置 Mapper Reducer 类型
		job.setMapperClass(MyMaxTempMapper.class);
		job.setReducerClass(MyMaxTempReducer.class);
		// 设置输入输出类型
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		
		// 开始执行Job
		// waitForCompletion 就是等待作业队列调度执行
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
